﻿using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Windows.Data.Json;

namespace NotWindowsStoreMetro
{
    public class StoreApp : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public int AppId { get; set; }

        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private StoreCategory _collection;
        public StoreCategory Collection
        {
            get
            {
                return this._collection;
            }

            set
            {
                if (this._collection != value)
                {
                    this._collection = value;
                    this.OnPropertyChanged("Collection");
                }
            }
        }

        private string _title = string.Empty;
        public string Title
        {
            get
            {
                return this._title;
            }

            set
            {
                if (this._title != value)
                {
                    this._title = value;
                    this.OnPropertyChanged("Title");
                }
            }
        }

        private string _subtitle = string.Empty;
        public string Subtitle
        {
            get
            {
                return this._subtitle;
            }

            set
            {
                if (this._subtitle != value)
                {
                    this._subtitle = value;
                    this.OnPropertyChanged("Subtitle");
                }
            }
        }

        private ImageSource _image = null;
        private Uri _imageUri = null;
        public ImageSource Image
        {
            get
            {
                if (_image == null && _imageUri != null)
                {
                    _image = new BitmapImage(_imageUri);
                }
                return this._image;
            }

            set
            {
                if (this._image != value)
                {
                    this._image = value;
                    this._imageUri = null;
                    this.OnPropertyChanged("Image");
                }
            }
        }

        public void SetImage(Uri imageUri)
        {
            _image = null;
            _imageUri = imageUri;
            this.OnPropertyChanged("Image");
        }

        private string _link = string.Empty;
        public string Link
        {
            get
            {
                return this._link;
            }

            set
            {
                if (this._link != value)
                {
                    this._link = value;
                    this.OnPropertyChanged("Link");
                }
            }
        }

        private string _category = string.Empty;
        public string Category
        {
            get
            {
                return this._category;
            }

            set
            {
                if (this._category != value)
                {
                    this._category = value;
                    this.OnPropertyChanged("Category");
                }
            }
        }

        private string _description = string.Empty;
        public string Description
        {
            get
            {
                return this._description;
            }

            set
            {
                if (this._description != value)
                {
                    this._description = value;
                    this.OnPropertyChanged("Description");
                }
            }
        }

        private string _content = string.Empty;
        public string Content
        {
            get
            {
                return this._content;
            }

            set
            {
                if (this._content != value)
                {
                    this._content = value;
                    this.OnPropertyChanged("Content");
                }
            }
        }

        private string _author = string.Empty;
        public string Author
        {
            get
            {
                return this._author;
            }

            set
            {
                if (this._author != value)
                {
                    this._author = value;
                    this.OnPropertyChanged("Author");
                }
            }
        }

        private string _uploaded = string.Empty;
        public string Uploaded
        {
            get
            {
                return this._uploaded;
            }

            set
            {
                if (this._uploaded != value)
                {
                    this._uploaded = value;
                    this.OnPropertyChanged("Uploaded");
                }
            }
        }

        private int _downloadCount = 0;
        public int DownloadCount
        {
            get
            {
                return this._downloadCount;
            }

            set
            {
                if (this._downloadCount != value)
                {
                    this._downloadCount = value;
                    this.OnPropertyChanged("DownloadCount");
                }
            }
        }
    }
}
